<?php
ini_set("error_reporting","E_ALL & ~E_NOTICE");
header('Content-type: application/json');
$jsoncallback = htmlspecialchars($_REQUEST ['jsoncallback']);//获取回调函数名

$url=$_GET["url"];$url = preg_replace('# #','',$url);
$title=$_GET["title"];$title = preg_replace('# #','',$title);
$description=$_GET["description"];$description = preg_replace('# #','',$description);
$keywords=$_GET["keywords"];$keywords = preg_replace('# #','',$keywords);
$type=$_GET["type"];$type = preg_replace('# #','',$type);
$state=$_GET["state"];$state = preg_replace('# #','',$state);
$token=$_GET["token"];$token = preg_replace('# #','',$token);

if ($state != "显示") {
    $state = "隐藏";
}

/*if (!$url and !$title and !$description and !$keywords and !$type) {
    $data['status']="NO";
    $data['message']="数据验证失败[关键字不能全部为空数值]，请您检查后重试！";
    echo $jsoncallback . "(" . json_encode($data, JSON_UNESCAPED_UNICODE) . ")";
    die();
}*/

if ($token != "Jmwpower") {
    $data['status']="NO";
    $data['message']="数据验证失败[Token 口令不正确]，请您检查后重试！";
    echo $jsoncallback . "(" . json_encode($data, JSON_UNESCAPED_UNICODE) . ")";
    die();
}

$servername = "localhost";
$username = "username";//需要修改为你的 数据
$password = "password";
$dbname = "dbname";

$con = new mysqli($servername, $username, $password, $dbname);
if (mysqli_connect_errno()){// 检测连接
    mysqli_close($con);//关闭数据库
    $data['status']="NO";
    $data['message']="链接数据库失败，请稍候刷新重试！";
    echo $jsoncallback . "(" . json_encode($data, JSON_UNESCAPED_UNICODE) . ")";
}else{//读取记录数据
    $sql = "SELECT * FROM `url` WHERE `url` like '%$url%' and `title` like '%$title%' and `description` like '%$description%' and `keywords` like '%$keywords%' and `type` like '%$type%' and `state` like '%$state%'";
    $result = $con->query($sql);
    if ($result->num_rows > 0) {
        $i=0;
        while($row = $result->fetch_assoc()) {
            $data[$i]["id"] = $row["id"];
            $data[$i]["title"] = $row["title"];
            $data[$i]["url"] = $row["url"];
            $data[$i]["description"] = $row["description"];
            $data[$i]["keywords"] = $row["keywords"];
            $data[$i]["type"] = $row["type"];
            $data[$i]["state"] = $row["state"];
            $i++;
        }
        echo $jsoncallback . "(" . json_encode($data, JSON_UNESCAPED_UNICODE) . ")";
    } else {
        $data['status']="NO";
        $data['message']="数据表中未查询到任何相关数据！";
        echo $jsoncallback . "(" . json_encode($data, JSON_UNESCAPED_UNICODE) . ")";
    }
    $con->close();//关闭数据库
}
?>